<template>
    <h2>用户借款</h2>
    <table class="table table-bordered">
        <tr>
            <td>借款款项名称</td>
            <td>{{state.B_Name  }}</td>
        </tr>
        <tr>
            <td>借款最高金额</td>
            <td>{{ state.B_Money }}</td>
        </tr>
        <tr>
            <td>利息</td>
            <td>{{ (state.I_Interest) }}</td>
        </tr>
        <tr>
            <td>借款金额</td>
            <td><input type="text" v-model="UB_Money"  /></td>
        </tr>
        <tr>
            <td>每月还款金额</td>
            <td>{{((Number(UB_Money)+(UB_Money*state.I_Interest/100))/12).toFixed(2) }}CNY</td>
        </tr>
        <tr>
            <td></td>
            <td><input type="button" value="确认借款" @click="add" /></td>
        </tr>

    </table>
  </template>
  
  <script setup lang="ts">
import{reactive,toRefs,onMounted} from 'vue'
import { useRouter,useRoute } from 'vue-router'
import axios from 'axios'
import {useUserStore} from '../../store/User'
//创建store对象
const userStore=useUserStore();
let route=useRoute()
let router=useRouter()
let data:any=reactive({
        state:{
           
        },
        UB_Money:'',
    })
let {state,UB_Money}=toRefs(data)
onMounted(()=>{
        show();

})
    //反填
 const show=()=>{
        axios({
            url:"/api/Borrow/GetBorrowMoneyList",
            method:'get',
            params:{
                id:route.query.id
            }
        })
        .then(res=>{
            console.log(res);
            state.value=res.data.data[0];
        })
        .catch(err=>{
            console.log(err);   
        })
}
const add=()=>{
    axios({
            url:"/api/Borrow/PostAddBorrow",
            method:'post',
            data:{
                B_Id:route.query.id,
                UB_Money:UB_Money.value,
                U_Id:userStore.userInfo.U_Id
            }
        })
        .then(res=>{
            console.log(res);
            if(res.data.data>0)
            {
                alert("借款成功");
                router.push("/main/userBorrowList")
            }
            else
            {
                alert("借款失败");
              return;
            }
        })
        .catch(err=>{
            console.log(err);   
        })
}
  </script>
  
  
  
  <style scoped>
  
  </style>